package com.mt.channel.service.model;

import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.github.pagehelper.PageHelper;
import com.mt.channel.entity.ChannelAdminRoleRelateEntity;
import com.mt.channel.mapper.ChannelAdminRoleRelateMapper;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;

@Component
public class ChannelAdminRoleRelateServiceModel {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ChannelAdminRoleRelateServiceModel.class);

    @Autowired
    private ChannelAdminRoleRelateMapper channelAdminRoleRelateMapper;

    public ServiceResult<List<ChannelAdminRoleRelateEntity>> selectList(Map<String, Object> params,
        PagerInfo<?> pagerInfo) {
        Assert.notNull(this.channelAdminRoleRelateMapper, "Property 'channelAdminRoleRelateMapper' is required.");
        ServiceResult<List<ChannelAdminRoleRelateEntity>> result =
            new ServiceResult<List<ChannelAdminRoleRelateEntity>>();
        try {
            if (pagerInfo != null) {
                PageHelper.startPage(pagerInfo.getPageIndex(), pagerInfo.getPageSize());
            }
            List<ChannelAdminRoleRelateEntity> channelAdminRoleRelateEntityResult =
                this.channelAdminRoleRelateMapper.selectList(params);
            result.setResult(channelAdminRoleRelateEntityResult);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelAdminRoleRelateServiceModel][selectList]：query selectList occur exception", e);
        }
        return result;
    }

    public ServiceResult<ChannelAdminRoleRelateEntity> selectInfo(Map<String, Object> params) {
        Assert.notNull(this.channelAdminRoleRelateMapper, "Property 'channelAdminRoleRelateMapper' is required.");
        ServiceResult<ChannelAdminRoleRelateEntity> result = new ServiceResult<ChannelAdminRoleRelateEntity>();
        try {
            result.setResult(this.channelAdminRoleRelateMapper.selectByPrimaryKey(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelAdminRoleRelateServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> insert(ChannelAdminRoleRelateEntity channelAdminRoleRelateEntity) {
        Assert.notNull(this.channelAdminRoleRelateMapper, "Property 'channelAdminRoleRelateMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.channelAdminRoleRelateMapper.insert(channelAdminRoleRelateEntity);
            if (save > 0) {
                id = channelAdminRoleRelateEntity.getChannelAdminRoleId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelAdminRoleRelateServiceModel][insert]：query insert occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateRelate(ChannelAdminRoleRelateEntity channelAdminRoleRelateEntity) {
        Assert.notNull(this.channelAdminRoleRelateMapper, "Property 'channelAdminRoleRelateMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.channelAdminRoleRelateMapper.updateByPrimaryKeySelective(channelAdminRoleRelateEntity);
            if (save > 0) {
                id = channelAdminRoleRelateEntity.getChannelAdminRoleId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error(
                "[ChannelAdminRoleRelateServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer>
        updateByPrimaryKeySelective(ChannelAdminRoleRelateEntity channelAdminRoleRelateEntity) {
        Assert.notNull(this.channelAdminRoleRelateMapper, "Property 'channelAdminRoleRelateMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.channelAdminRoleRelateMapper.updateByPrimaryKeySelective(channelAdminRoleRelateEntity);
            if (save > 0) {
                id = channelAdminRoleRelateEntity.getChannelAdminRoleId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error(
                "[ChannelAdminRoleRelateServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateByPrimaryKey(ChannelAdminRoleRelateEntity channelAdminRoleRelateEntity) {
        Assert.notNull(this.channelAdminRoleRelateMapper, "Property 'channelAdminRoleRelateMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.channelAdminRoleRelateMapper.updateByPrimaryKey(channelAdminRoleRelateEntity);
            result.setResult(channelAdminRoleRelateEntity.getChannelAdminRoleId());
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelAdminRoleRelateServiceModel][updateByPrimaryKey]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> deleteByPrimaryKey(Integer channelAdminRoleId) {
        Assert.notNull(this.channelAdminRoleRelateMapper, "Property 'channelAdminRoleRelateMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int save = 0;
        try {
            save = this.channelAdminRoleRelateMapper.doUpdateByPrimaryKey(channelAdminRoleId);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelAdminServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
            throw new RuntimeException(e.getMessage());
        }
        return result;
    }
}
